﻿using System;
using System.Data;
using DataAccess;

namespace Business
{
    public class CategoryBsl
    {
        private CategoryDao _categoryDao;
        /// <summary>
        /// Initializes a new instance of the <see cref="CategoryBsl"/> class.
        /// </summary>
        public CategoryBsl()
        {
            _categoryDao = new CategoryDao();
        }

        /// <summary>
        /// Views all categories.
        /// </summary>
        /// <returns></returns>
        public DataTable ViewAllCategories()
        {
            try
            {
                return _categoryDao.ViewAllCategory();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Creates the category.
        /// </summary>
        /// <param name="cateName">Name of the cate.</param>
        /// <param name="cateDesc">The cate desc.</param>
        /// <param name="status">if set to <c>true</c> [status].</param>
        /// <returns></returns>
        public bool CreateCategory(string categoryName, string categoryDescription, bool status)
        {
            try
            {
                int result = _categoryDao.CreateCategory(categoryName, categoryDescription, status);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Updates the category.
        /// </summary>
        /// <param name="categoryId">The category id.</param>
        /// <param name="categoryName">Name of the category.</param>
        /// <param name="categoryDescription">The category description.</param>
        /// <param name="status">if set to <c>true</c> [status].</param>
        /// <returns></returns>
        public bool UpdateCategory(int categoryId, string categoryName, string categoryDescription, bool status)
        {
            try
            {
                int result = _categoryDao.UpdateCategory(categoryId, categoryName, categoryDescription, status);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Deletes the category.
        /// </summary>
        /// <param name="cateId">The cate id.</param>
        /// <returns></returns>
        public bool DeleteCategory(int categoryId)
        {
            try
            {
                int result = _categoryDao.DeleteCategory(categoryId);
                return (result != 0);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Views the category name by id.
        /// </summary>
        /// <param name="cateId">The cate id.</param>
        /// <returns></returns>
        public string ViewCategoryNameById(int categoryId)
        {
            try
            {
                return _categoryDao.ViewCategoryNameById(categoryId);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Views the name of the category id by.
        /// </summary>
        /// <param name="cateName">Name of the cate.</param>
        /// <returns></returns>
        public int ViewCategoryIdByName(string categoryName)
        {
            try
            {
                return _categoryDao.ViewCategoryIdByName(categoryName);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        /// <summary>
        /// Views the post by category id.
        /// </summary>
        /// <param name="cateId">The cate id.</param>
        /// <returns></returns>
        public DataTable ViewPostByCategoryId(int categoryId)
        {
            try
            {
                return _categoryDao.ViewPostByCategoryId(categoryId);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
